package com.itheima.sc.web.sms;

import com.itheima.sc.dto.CouponDto;
import com.itheima.sc.result.Result;
import com.itheima.sc.service.sms.SmsCouponService;
import com.itheima.sc.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/coupon")
public class SmsCouponController {

    @Autowired
    private SmsCouponService couponService;

    //添加优惠券
    @PostMapping("/create")
    public Result addCoupon(@RequestBody CouponDto couponDto) {
        couponService.addCoupon(couponDto);
        return Result.success(null);
    }
    //删除优惠券
    @PostMapping("/delete/{id}")
    public Result deleteCoupon(@PathVariable("id")Long id) {
        couponService.deleteCoupon(id);
        return Result.success(null);
    }
    //根据优惠券名称和类型分页获取优惠券列表
    @GetMapping("/list")
    public Result selectCouponList(@RequestParam Map<String,String> param){
        PageResult pageResult=couponService.selectCouponList(param);
        return Result.success(pageResult);
    }
    //修改优惠券
    @PostMapping("/update/{id}")
    public Result updateCoupon(@PathVariable("id")Long id,@RequestBody CouponDto couponDto) {
        couponService.updateCoupon(id,couponDto);
        return Result.success(null);
    }
    //查询优惠券详情
    @GetMapping("/{id}")
    public Result selectCouponInfo(@PathVariable("id")Long id) {
       CouponDto couponDto= couponService.selectCouponInfo(id);
        return Result.success(couponDto);
    }
}
